/**
 *       Copyright (c) 2012 Lukas Zaruba
 *
 *   This file is part of Robot Playground.
 *
 *   Robot Playground is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Robot Playground is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with Robot Playground. If not, see <http://www.gnu.org/licenses/>.
 */
package net.zarubsys.commons.scripting.variables;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import net.zarubsys.commons.scripting.ScriptingException;

/**
 * Based on scripting language from Media Solutions Slovakia, a.s.
 * @author Lukas Zaruba, lukas.zaruba@gmail.com
 */
public class MapVariablePool implements IVariablePool {
	
	private Map<String, Object> variables;
	private final String name;

	public MapVariablePool(String name, Map<String, Object> initialContent) {
		if (initialContent == null) throw new IllegalArgumentException("Initial content must not be null!");
		this.name = name;
		this.variables = initialContent;
	}

	public MapVariablePool(String name) {
		this(name, new HashMap<String, Object>());
	}

	@Override
	public Object getProperty(String propertyName) throws ScriptingException {
		Object value = variables.get(propertyName);
		return value == null ? null : value;
	}

	@Override
	public boolean isPropertySet(String propertyName) throws ScriptingException {
		return variables.containsKey(propertyName);
	}

	@Override
	public void removeProperty(String propertyName) throws ScriptingException {
		variables.remove(propertyName);
		
	}

	@Override
	public void setProperty(String propertyName, Object value) throws ScriptingException {
		variables.put(propertyName, value);
	}

	@Override
	public Set<String> getPropertyList() {
		return variables.keySet();
	}

	@Override
	public String getPoolName() {
		return name;
	}
	
}